package com.activemq.cluster;

import cn.hutool.core.date.DateUtil;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

public class ClusterProd {
    public static final String CLUSTER_URL = "failover:(tcp://wangweiye:61616,tcp://wangwy:61616,tcp://192.168.222.211:61616)?randomize=false";
    public static final String QUEUE_NAME = "queue-cluster";

    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(CLUSTER_URL);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(QUEUE_NAME);
        MessageProducer producer = session.createProducer(queue);
        for (int i = 0; i < 3; i++) {
            producer.send(session.createTextMessage("集群队列测试:" + DateUtil.now() + "+" + i));
        }
        producer.close();
        session.close();
        connection.close();
    }
}
